﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;

namespace RemoveRelatedNews
{
	public partial class RemoveRelateNews
	{
		private string _DataContent = null;
		public string DataContent 
		{
			get
			{
				return _DataContent;
			}
			set
			{
				_DataContent = value;
			}
		}
		internal RemoveRelateNews(string html, string xPath, string KWSpecial1, string KWSpecial2)
		{
			var CurrentHtml = Remove_RelatedNews(html, xPath, KWSpecial1, KWSpecial2);
			this._DataContent = CurrentHtml;
		}
		private string Remove_RelatedNews(string Html, string xPath, string KeywordsSpecial1, string KeywordsSpecial2)
		{
			HtmlDocument htmlSnippet = new HtmlDocument();
			var CurrentHtml = Html;
			if (!string.IsNullOrEmpty(KeywordsSpecial1))
			{
				CurrentHtml = Html.Replace(KeywordsSpecial1, "");
			}
			if (!string.IsNullOrEmpty(KeywordsSpecial2))
			{
				CurrentHtml = Html.Replace(KeywordsSpecial2, "");
			}
			htmlSnippet.LoadHtml(CurrentHtml);
			var resultRemoveLink = htmlSnippet.DocumentNode.SelectNodes(xPath);
			if (resultRemoveLink != null)
			{
				foreach (HtmlNode link in htmlSnippet.DocumentNode.SelectNodes(xPath))
				{
					link.RemoveAll();
				}
				return htmlSnippet.DocumentNode.WriteContentTo();
			}
			return Html;
		}
	}
}
